<template>
  <div class="recommend" ref="container">
    <div class="title acea-row row-center-wrapper">
      <span class="iconfont icon-zhuangshixian"></span>
      <span class="name">为你推荐</span>
      <span class="iconfont icon-zhuangshixian lefticon"></span>
    </div>
    <div class="recommendList acea-row row-between-wrapper">
      <router-link
        :to="{ path: '/detail/' + item.id }"
        class="item"
        v-for="(item, index) in hostProduct"
        :key="index"
      >
        <div class="pictrue">
          <img :src="item.image" class="image" />
        </div>
        <div class="name line1">{{ item.store_name }}</div>
        <div class="money font-color-red">
          ￥<span class="num">{{ item.price }}</span>
        </div>
      </router-link>
    </div>
    <Loading :loaded="loadend" :loading="loading"></Loading>
  </div>

  <!-- <el-row type="flex" class="recommend" justify="center">
    <el-col :span="18" >
        <div class="main">
          <div class="title">
            <span>你可能喜欢</span>
          </div>
          <div class="slickWarp">
            <el-carousel :interval="5000" indicator-position="none"  arrow="hover" height="349px">
              <el-carousel-item v-for="item in page" :key="item" @change="">
                <div class="slic-list acea-row row-column-between">
                  <router-link
                    :to="{ path: '/detail/' + item.id }"
                    class="item"
                    v-for="(item, index) in hostProduct"
                    :key="index"
                   >
                    <div class="product">
                      <div class="pic">
                        <el-image :src="item.image" ></el-image>
                      </div>
                    </div>
                  </router-link>
                </div>
              </el-carousel-item>
            </el-carousel>
          </div>
        </div>
    </el-col>
</el-row> -->
</template>
<script>
import { getHostProducts } from "@api/store";
import Loading from "@components/Loading";
export default {
  name: "Recommend",
  props: {},
  components: {
    Loading
  },
  data: function() {
    return {
      hostProduct: [],
      page: 1,
      limit: 4,
      loadTitle: "",
      loading: false,
      loadend: false,
      maxNum:0
    };
  },
  mounted: function() {
    this.hostProducts();
    this.$scroll(this.$refs.container.parentElement, () => {
      !this.loading && this.hostProducts();
    });
  },
  methods: {
    hostProducts: function() {
      let that = this;
      if (that.loading) return; //阻止下次请求（false可以进行请求）；
      if (that.loadend) return; //阻止结束当前请求（false可以进行请求）；
      that.loading = true;
      getHostProducts(that.page, that.limit).then(res => {
        that.loading = false;
        //apply();js将一个数组插入另一个数组;
        that.hostProduct.push.apply(that.hostProduct, res.data);
        that.maxNum=res.data.length;
        that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成；
        if(!that.loadend){
          // that.maxNum=that.maxNum+res.data.length;
          that.page = that.page + 1;
        }
        that.page = that.page + 1;
        console.log("page"+that.page);
        console.log("maxNum"+that.maxNum);
      });
    }
  }
};
</script>
<style scoped>
  .recommend {
    background-color: #ffffff;
  }
  .recommend .main {
    width: 1090px;
    height: 397px;
    border: 1px solid #e8e8e8;
    margin: 0 auto;
  }
  .recommend .main .title{
    height: 44px;
    width: 1088px;
    line-height: 44px;
    font-size: 17px;
    background-color: #f5f5f5;
    padding-left: 20px;
  }
  .recommend .main .slickWarp {
    width: 1088px;
    height: 349px;
  }
  .recommend .main .slickWarp .slic-list {
    overflow: hidden;
    height: 488px;
    width: 960px;
    margin: 0 auto;
    margin-top: -180px;
    padding-top: 190px;
    pointer-events: none;
  }
  .recommend .main .slickWarp .slic-list .product {
    width: 210px;
    height: 279px;
  }
  .recommend .main .slickWarp .slic-list .product .pic {
    width: 210px;
    height: 210px;
  }
</style>
